<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="service.UseOrderService" %>
<%@ page import="service.DriversService" %>
<%@ page import="service.EmployeeService" %>
<%@ page import="beans.UseOrder" %>
<%@ page import="beans.Employee" %>
<%
    // 检查session是否存在
    if(session.getAttribute("username") == null) {
        response.sendRedirect(request.getContextPath() + "/login.jsp");
        return;
    }
    String username = (String)session.getAttribute("username");
    String role = (String)session.getAttribute("role");
    Object user = session.getAttribute("user");
    int driverId = Integer.parseInt(username); // 获取当前登录司机的ID

    // 获取订单ID
    String orderId = request.getParameter("orderId");
    UseOrderService orderService = new UseOrderService();
    DriversService driversService = new DriversService();
    EmployeeService employeeService = new EmployeeService();
    UseOrder order = null;
    String driverName = "";
    String reviewerName = "";

    try {
        order = orderService.getOrderById(orderId);
        if (order != null) {
            driverName = driversService.getDriverNameById(order.getDriverId());
            // 获取审核人信息
            if (order.getReviewer() != null) {
                Employee reviewer = employeeService.getEmployeeByID(order.getReviewer());
                if (reviewer != null) {
                    reviewerName = reviewer.getEmployeeName();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>订单详情 - 公司用车管理系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        /* 全局样式 */
        body {
            margin: 0;
            padding: 0;
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: #f6f6f6;
            color: #333;
        }

        /* 头部样式 */
        .header {
            background: #183a8a;
            color: #fff;
            font-size: 2rem;
            font-weight: bold;
            padding: 10px 0 10px 10px;
            letter-spacing: 2px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .header-right {
            display: flex;
            align-items: center;
            margin-right: 30px;
            font-size: 1rem;
        }
        .user-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #fff;
            color: #183a8a;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            margin-right: 10px;
        }
        .user-info {
            margin-right: 20px;
            color: #fff;
        }
        .bell-icon {
            font-size: 1.3rem;
            margin-right: 20px;
            color: #fff;
        }
        .logout {
            color: #fff;
            text-decoration: none;
            margin-left: 10px;
            font-size: 1rem;
            padding: 8px 15px;
            border-radius: 4px;
            background: rgba(255,255,255,0.1);
            transition: background 0.3s ease;
        }
        .logout:hover {
            background: rgba(255,255,255,0.2);
        }

        /* 主体容器 */
        .container {
            display: flex;
            height: calc(100vh - 56px);
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 220px;
            background: #183a8a;
            display: flex;
            flex-direction: column;
            padding-top: 10px;
            box-shadow: 2px 0 8px rgba(24,58,138,0.05);
        }
        .menu-item {
            color: #fff;
            padding: 18px 0 18px 32px;
            font-size: 1.15rem;
            cursor: pointer;
            border-left: 5px solid transparent;
            transition: background 0.2s, border 0.2s;
            text-decoration: none;
            display: flex;
            align-items: center;
        }
        .menu-item i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
        }
        .menu-item.active, .menu-item:hover {
            background: #2450a7;
            border-left: 5px solid #fff;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(24,58,138,0.10);
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            background: #fff;
            border: 2px solid #3ba0e9;
            border-left: none;
            padding: 30px;
            overflow-y: auto;
        }
        .page-title {
            font-size: 2.2rem;
            color: #183a8a;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 2px solid #eee;
            position: relative;
        }
        .page-title::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 100px;
            height: 2px;
            background: #3ba0e9;
        }

        /* 订单详情样式 */
        .info-item {
            margin-bottom: 15px;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 4px;
            transition: all 0.3s ease;
        }
        .info-item:hover {
            background: #e9ecef;
            transform: translateX(5px);
        }
        .info-item label {
            font-weight: bold;
            color: #183a8a;
            display: inline-block;
            width: 120px;
            margin-right: 15px;
        }
        .info-item span {
            color: #495057;
        }
        .back-btn {
            display: inline-block;
            margin-top: 30px;
            padding: 12px 25px;
            background-color: #183a8a;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            font-weight: bold;
            transition: all 0.3s ease;
            text-align: center;
        }
        .back-btn:hover {
            background-color: #2450a7;
            transform: translateY(-2px);
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }
        .error-message {
            text-align: center;
            color: #dc3545;
            margin: 20px 0;
            padding: 15px;
            background: #f8d7da;
            border-radius: 4px;
            border: 1px solid #f5c6cb;
        }
        .status-badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 14px;
            font-weight: bold;
        }
        .status-pending {
            background-color: #ffeeba;
            color: #856404;
        }
        .status-approved {
            background-color: #d4edda;
            color: #155724;
        }
        .status-rejected {
            background-color: #f8d7da;
            color: #721c24;
        }
        .status-completed {
            background-color: #cce5ff;
            color: #004085;
        }
    </style>
</head>
<body>
    <div class="header">
        <div>公司用车管理系统</div>
        <div class="header-right">
            <div class="user-icon">👤</div>
            <div class="user-info">工号：<%=username%></div>
            <div class="bell-icon">🔔</div>
            <a href="<%=request.getContextPath()%>/login.jsp" class="logout">退出登录</a>
        </div>
    </div>

    <div class="container">
        <div class="sidebar">
            <a class="menu-item" href="${pageContext.request.contextPath}/DriversServlet?action=1234">
                <i class="fas fa-home"></i>系统首页
            </a>
            <a class="menu-item" href="${pageContext.request.contextPath}/DriversServlet?action=a">
                <i class="fas fa-user"></i>个人中心
            </a>
            <a class="menu-item active" href="${pageContext.request.contextPath}/DriversServlet?action=c">
                <i class="fas fa-list"></i>全部订单
            </a>
            <a class="menu-item" href="${pageContext.request.contextPath}/DriversServlet?action=d">
                <i class="fas fa-tools"></i>维修单提交
            </a>
            <a class="menu-item" href="${pageContext.request.contextPath}/DriversServlet?action=e">
                <i class="fas fa-money-bill"></i>用车费用提交
            </a>
        </div>

        <div class="main-content">
            <h1 class="page-title">订单详情</h1>

            <% if (order != null) { %>
                <div class="info-item">
                    <label>订单编号：</label>
                    <span><%= order.getOrderId() %></span>
                </div>
                <div class="info-item">
                    <label>申请人：</label>
                    <span>员工<%= order.getEmployeeId() %></span>
                </div>
                <div class="info-item">
                    <label>用车时间：</label>
                    <span><%= new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(order.getExpectedDepartureTime()) %></span>
                </div>
                <div class="info-item">
                    <label>预计归还时间：</label>
                    <span><%= new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(order.getExpectedReturnTime()) %></span>
                </div>
                <div class="info-item">
                    <label>用车事由：</label>
                    <span><%= order.getUsageReason() %></span>
                </div>
                <div class="info-item">
                    <label>目的地：</label>
                    <span><%= order.getDestination() %></span>
                </div>
                <div class="info-item">
                    <label>随行人员：</label>
                    <span><%= order.getPassengers() %></span>
                </div>
                <div class="info-item">
                    <label>状态：</label>
                    <span class="status-badge status-<%= order.getReviewStatus().toLowerCase() %>"><%= order.getReviewStatus() %></span>
                </div>
                <div class="info-item">
                    <label>车辆ID：</label>
                    <span><%= order.getVehicleId() %></span>
                </div>
                <div class="info-item">
                    <label>司机姓名：</label>
                    <span><%= driverName %></span>
                </div>
                <% if (order.getReviewer() != null) { %>
                <div class="info-item">
                    <label>审核人：</label>
                    <span><%= reviewerName %></span>
                </div>
                <% } %>

                <a href="${pageContext.request.contextPath}/DriversServlet?action=c" class="back-btn">返回列表</a>
            <% } else { %>
                <div class="error-message">
                    <p>未找到订单信息或无权查看此订单</p>
                </div>
                <a href="${pageContext.request.contextPath}/DriversServlet?action=c" class="back-btn">返回列表</a>
            <% } %>
        </div>
    </div>
</body>
</html> 